package com.odais.AE_Modifier;

import java.util.ArrayList;

import org.andengine.entity.Entity;
import org.andengine.entity.sprite.Sprite;

import com.odais.AE_Planner.Position;
import com.odais.Reservation.ReservationBox;
import com.odais.Reservation.ReservationEntity;

public class FlowerSplitAngleCalc
{
// ===========================================================
// Constants
// ===========================================================
	protected static final float LENGHT_X = 100;
	protected static final float LENGHT_Y = 100;

// ===========================================================
// Fields
// ===========================================================

	private float sceneCenterX, sceneCenterY;
	private float pX, pY, initialX, initialY;
	private double deltaX, deltaY, angle, deltaAngle, angleOffset;

	private ArrayList<ReservationEntity> items;

	private Position mPosition;
	private ArrayList<Position> shiftedPositions;

// ===========================================================
// Constructors
// ===========================================================

	public FlowerSplitAngleCalc() {
		super();
		this.sceneCenterX = 0;
		this.sceneCenterY = 0;
		this.items = null;

		pX = 0;
		pY = 0;

	}

	public FlowerSplitAngleCalc(float sceneCenterX, float sceneCenterY,
			ArrayList<ReservationEntity> reservationEntityList) {
		super();
		this.sceneCenterX = sceneCenterX;
		this.sceneCenterY = sceneCenterY;
		this.items = reservationEntityList;

		shiftedPositions = new ArrayList<Position>();

		initialX = this.items.get(0).getReservationBox_RightPanel().getX();
		initialY = this.items.get(0).getReservationBox_RightPanel().getY();

		deltaX = this.sceneCenterX - initialX;
		deltaY = this.sceneCenterY - initialY;
		angle = Math.atan(deltaY/deltaX);
		if(deltaX<0)
			angle = angle + Math.PI;

		//Make it twice for entire flower
		deltaAngle = (Math.PI / this.items.size());
		angleOffset = ((int)this.items.size()/2) * deltaAngle;
		angle = angle - angleOffset;

		for(int i=0; i<this.items.size(); i++)
		{
			pX = (float) (LENGHT_X * Math.cos(angle + deltaAngle * i));
			pY = (float) (LENGHT_Y * Math.sin(angle + deltaAngle * i));
			mPosition = new Position(pX, pY);
			shiftedPositions.add(mPosition);
		}
	}

// ===========================================================
// Getter & Setter
// ===========================================================

	public ArrayList<Position> getShiftedPositions() {
		return shiftedPositions;
	}

	public ArrayList<ReservationEntity> getItems() {
		return items;
	}

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

}